tongfusoft.profileDocCheckIn = function() {
}

tongfusoft.profileDocCheckIn.prototype = {

		init : function() {
		      $("#selectFile").html(this.selectFileHtml1);
		    		
		      $('.filestyle').filestyle({buttonText:'选择文件'});
		},
	    selectFileHtml1:"<input id='fileupload_input' type='file' data-buttonText='选择文件' required='' minlength='1' data-classbutton='btn btn-default' data-classinput='form-control inline' class='form-control filestyle' />",
	    selectFileHtml2:"  <div class='bootstrap-filestyle  input-group'><input class='form-control'required='' id='selectFileName' disabled type='text'><span class='input-group-btn'><button onclick=' new tongfusoft.serverFileList().openFileListPage()' type='button' class='  btn btn-default'><em class='fa fa-folder-open'></em>选择文件</button></span></div>",
		selectUploadModel:function(){
			var sfh1 = this.selectFileHtml1;
			var sfh2 = this.selectFileHtml2;
			$("input[name='uploadMode']").on("change",function(){
				$("#selectFileId").val('');
				$("#selectFile").empty();
				if($('input:radio[name="uploadMode"]:checked').val()=='1'){
					 $("#selectFile").html(sfh1);
					 $('.filestyle').filestyle({buttonText:'选择文件'});
		    	}else{
		    		 $("#selectFile").html(sfh2);
		    	}
				
			})
		},
	submit : function() {
		


		$.validator.setDefaults({
			submitHandler : function() {

				var formData = new FormData();

				$.map(common.getFormData("dcoForm"), function(v, k) {

					formData.append(k, v);

				})
				formData.append("docFolder",$("#selectFolderId").val());
				var docMetadata=common.getFormDataByClass("profileMetaData");
				docMetadata["uploadMode"]=$('input:radio[name="uploadMode"]:checked').val()
				if($('input:radio[name="uploadMode"]:checked').val()=='1'){
					formData.append('file', $('#fileupload_input')[0].files[0]);
				}else{
					docMetadata["selectFileId"]=$("#selectFileId").val();
				}
				formData.append('docMetadata',JSON.stringify(docMetadata));
				$.ajax({
					url : common.getContextPath('docCheckIn/upload'),
					type : 'POST',
					cache : false,
					data : formData,
					processData : false,
					contentType : false,
					success : function(data) {
						if(data.state=='success'){
							toastr["success"]("保存成功");
							window.location.href = common.getContextPath('mydoc');
						}else if(data.state=="error"){
							if(data.code=='write_power_error'){
								
								toastr["error"]('操作权限不足');
								
							}
						}
					}

				})

			
				
			}
		});
		$("#dcoForm").validate();

		$("#submitBtn").click(function() {

			$("#dcoForm").submit();
		})

	},
	dataMete : function() {

		$('.dateclass').datetimepicker({
			format : 'YYYY-MM-DD HH:mm',
			icons : {
				time : 'fa fa-clock-o',
				date : 'fa fa-calendar',
				up : 'fa fa-chevron-up',
				down : 'fa fa-chevron-down',
				previous : 'fa fa-chevron-left',
				next : 'fa fa-chevron-right',
				today : 'fa fa-crosshairs',
				clear : 'fa fa-trash'
			}
		});
	},
	selectData : function() {

		$.each($(".selectData"), function(index, item) {
			if ($("#" + $(item).attr("id")+"_data").val() != null || $("#" + $(item).attr("id")+"_data").val() != '') {
				var vals = $("#" + $(item).attr("id")+"_data").val().split(",");

				$("#" + $(item).attr("id")).empty();
				var option = "<option value=''></option>";
				for (var i = 0; i < vals.length; i++) {

					option = option + "<option value='" + vals[i] + "'>" + vals[i] + "</option>";
				}
				$("#" + $(item).attr("id")).html(option);
			}
		});
	},
	returnBtn:function(){
		
		$("#returnBtn").click(function() {

			window.location.href=common.getContextPath('mydoc');
		})
		
		
		
	}
}

$(function() {
	var obj = new tongfusoft.profileDocCheckIn();
	obj.init();
	obj.submit();
	obj.dataMete();
	obj.selectData();
	obj.returnBtn();
	obj.selectUploadModel();
	var obj2=new  tongfusoft.serverFileList();
	obj2.fileList();
	obj2.selectedFile();
	
	obj2.openFolderPage();
	obj2.selectFolderBtn();
	
})